<?php

namespace app\model\platform;

use app\BaseModel;
use app\model\TaskModel;
use app\model\UnitModel;
use app\model\UserModel;
use think\model\relation\BelongsTo;

/**
 * 区域-任务单位
 */
class PlatformTaskUnitModel extends BaseModel
{
    protected $name = 'platform_task_unit';

    /**
     * 单位
     * @return BelongsTo
     */
    public function unit(): BelongsTo
    {
        return $this->belongsTo(UnitModel::class,'unit_id')->bind([
            'unit_name' => 'name',
            'unit_banner' => 'banner',
            'province_name',
            'city_name',
            'area_name',
            'unit_level' => 'level',
        ]);
    }


    /**
     * 单位任务
     * @return BelongsTo
     */
    public function UnitTask(): BelongsTo
    {
        return $this->belongsTo(TaskModel::class,'unit_task_id')->bind([
            'unit_task_name' => 'name',
            'unit_task_user_count' => 'user_count',
            'unit_task_user_complete_num' => 'user_complete_num',
            'unit_task_user_complete_rate' => 'user_complete_rate',
            'unit_task_warning_num' => 'warning_num',
            'unit_task_user_name' => 'user_name',
        ]);
    }

    /**
     * 单位任务-详情
     * @return BelongsTo
     */
    public function UnitTaskInfo(): BelongsTo
    {
        return $this->belongsTo(TaskModel::class,'unit_task_id');
    }

    /**
     * 区域-任务
     * @return BelongsTo
     */
    public function task(): BelongsTo
    {
        return $this->belongsTo(PlatformTaskModel::class,'task_id')->bind([
            'task_name' => 'name',
            'start_time',
            'end_time',
            'describe',
            'price',
            'rating_scale_count',
            'unit_count',
            'unit_complete_num',
            'unit_complete_rate',
            'is_has_after',
            'result_read_auth',
            'status',
            'task_time' => 'time',
            'user_level',
            'user_name'
        ]);
    }

    /**
     * 提交报告用户
     * @return BelongsTo
     */
    public function SubmitUser(): BelongsTo
    {
        return $this->belongsTo(UserModel::class,'submit_uid')->bind([
            'submit_user_name' => 'name',
            'submit_role_name' => 'role_name',
        ]);
    }

}